<?php

class DBMAttributeTranslator implements DBMTranslator {
	/**
	 * Translate the attribute the SQL Server notation
	 *
	 * @param DBMAttribute $attribute
	 */
	public static function translateToSQLServer($attribute, $command = null){
		// check if the attribute has a column
		if($attribute->getColumn() == null){
			return null;
		}
		
		 // get the father entity
		$entity = $attribute->getEntity();
		
		// check the operation
		if($command != null && $command->getOperation() == DBMOperations::UPDATE){
			// format and return 
			return sprintf("%s = %s", $attribute->getColumn(), DBMGeneralTranslator::translateToSQLServer($attribute->getValue(), $command));
		} elseif($command != null && $command->getOperation() == DBMOperations::INSERT){
			// format and return
			return sprintf("%s", $attribute->getColumn());
		} else {
			// format and return 
			return sprintf("%s.%s as %s", $entity->getAlias(), $attribute->getColumn(), $attribute->__toString());
		}
	}
	
	/**
	 * Translate the attribute to MySQL notation
	 * @param DBMAttribute $attribute
	 * @param unknown_type $command
	 */
	public static function translateToMySQL($attribute, $command = null){
		// check if the attribute has a column
		if($attribute->getColumn() == null){
			return null;
		}
		
		 // get the father entity
		$entity = $attribute->getEntity();
		
		// check the operation
		if($command != null && $command->getOperation() == DBMOperations::UPDATE){
			// format and return 
			return sprintf("%s = %s", $attribute->getColumn(), DBMGeneralTranslator::translateToMySQL($attribute->getValue(), $command));
		} elseif($command != null && $command->getOperation() == DBMOperations::INSERT){
			// format and return
			return sprintf("%s", $attribute->getColumn());
		} else {
			// format and return 
			return sprintf("%s.%s as %s", $entity->getAlias(), $attribute->getColumn(), $attribute->__toString());
		}
	}
	
	public static function translateToPostgreSQL($entity, $command = null){
		// check if the attribute has a column
		if($attribute->getColumn() == null){
			return null;
		}
		
		 // get the father entity
		$entity = $attribute->getEntity();
		
		// check the operation
		if($command != null && $command->getOperation() == DBMOperations::UPDATE){
			// format and return 
			return sprintf("%s = %s", $attribute->getColumn(), DBMGeneralTranslator::translateToPostgreSQL($attribute->getValue(), $command));
		} elseif($command != null && $command->getOperation() == DBMOperations::INSERT){
			// format and return
			return sprintf("%s", $attribute->getColumn());
		} else {
			// format and return 
			return sprintf("%s.%s as %s", $entity->getAlias(), $attribute->getColumn(), $attribute->__toString());
		}
	}
}

?>